package com.itheima.a10demopolymorphsm;

public class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void keepPet(Animal a,String food){
        //Animal a如果是狗,那就强转成Dog d(强转成狗,叫d)
        if(a instanceof Dog d){
            System.out.println("年龄为" + age + "岁的" + name + "养了一只" + a.getColor() + "的" + a.getAge() + "岁的🐕");
            d.eat(food);
        }else if(a instanceof Cat c){
            System.out.println("年龄为" + age + "岁的" + name + "养了一只" + c.getColor() + "的" + c.getAge() + "岁的🐱");
            c.eat(food);
        }else{
            System.out.println("没有这种动物");
        }

    }

}
